<%@page import="com.feib.soeasy.util.CodeTableUtil"%>
<%@page import="com.feib.soeasy.model.UploadFile"%>
<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<c:choose>
	<c:when test="${null != actionBean.queryColumnValidateErrorResult && not empty actionBean.queryColumnValidateErrorResult.paginatedList}">
		<c:set var="lastPageNumber" value="${actionBean.queryColumnValidateErrorResult.totalPageCount}"/>
		<c:set var="currentPageNumber" value="${actionBean.queryColumnValidateErrorResult.pageNumber}"/>
		<c:set var="prePageNumber" value="${actionBean.queryColumnValidateErrorResult.pageNumber - 1}"/>
		<c:set var="nextPageNumber" value="${actionBean.queryColumnValidateErrorResult.pageNumber + 1}"/>
		<table id="listTable">
			<thead>
				<tr>
					<th id="paginationBar" colspan="10">
						<input type="button" id="columnError.firstPageBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
						<input type="button" id="columnError.prePageBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
						第 <input type="text" id="columnError.currentPageText" value="${currentPageNumber }" size="3" maxlength="4"> / ${lastPageNumber} 頁
						<input type="button" id="columnError.nextPageBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
						<input type="button" id="columnError.lastPageBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
					</th>
				</tr>
				<tr>
					<th>行號</th>
					<th>欄位</th>
					<th>錯誤原因</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${actionBean.queryColumnValidateErrorResult.paginatedList}" var="viewObj" varStatus="rowstat">
				<tr>
					<td>第&nbsp;<c:out value="${viewObj.lineNumber}" />&nbsp;行</td>
					<td><c:out value="${viewObj.columnName}" /></td>
					<td><c:out value="${viewObj.errorMessage}" /></td>					
				</tr>
				</c:forEach>
			</tbody>
		</table>
			
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$("[id^='columnError.firstPageBtn']").click(function() {
				doQueryFileErrorReasonAction(1);
			});
			
			$("[id^='columnError.prePageBtn']").click(function() {
				doQueryFileErrorReasonAction(<c:out value='${prePageNumber}'/>);
			});
			
			$("[id^='columnError.nextPageBtn']").click(function() {
				doQueryFileErrorReasonAction(<c:out value='${nextPageNumber}'/>);
			});
			
			$("[id^='columnError.lastPageBtn']").click(function() {
				doQueryFileErrorReasonAction(<c:out value='${lastPageNumber}'/>);
			});
			
			$("[id^='columnError.currentPageText']").change(function() {
				var value = this.value;
				if (value != ''){
					value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
					var intRegex = /^\d+$/;
					if(!intRegex.test(value)) {
						alert('頁數必須是整數');
						return ;
					}
					
					value = parseInt(value, 10);
					
					if (value < 1){
						alert('頁數必須是大於1');
						return ;
					}
					else if (value > <c:out value='${lastPageNumber}'/>){
						alert('頁數必須是小於總頁數 (<c:out value='${lastPageNumber}'/>)');
						return ;
					}
					else if (value != <c:out value='${currentPageNumber}'/>){
						doQueryFileErrorReasonAction(value);
					}
					
				}
				else{
					alert('頁數不可為空白');
					return ;
				}
			});

			//$( "#errorReasonsOfFileDiv" ).dialog( "destroy" );
			$( "#errorReasonsOfFileDiv" ).dialog({  title:'檢核未通過原因' ,width: 600, resizable: true, modal: true  });
			
		});
		//-->
		</script>
	</c:when>
	<c:otherwise>
		<div id="queryNothingBlockDiv" style="display: none;">
			查無資料
		</div>		
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			//$( "#queryNothingBlockDiv" ).dialog( "destroy" );
			$( "#queryNothingBlockDiv" ).dialog({  title:'檢核未通過原因' ,width: 300, height : 100, resizable: false, modal: true  });
		});
		//-->
		</script>
	</c:otherwise>
</c:choose>